
<script>
	$(function() {
		$( "#datefrom" ).datepicker();
		$( "#dateto" ).datepicker();
	});
	$(document).ready(function(){
		<!--
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		$( "#dateto" ).val(month + "/" + day + "/" + year)
		//-->
	});
	</script>

<script type="text/javascript">
$(document).ready(function(){
	  $('#ItemCategoryId').live('change', function() {
	    if($(this).val().length != 0) {
		    console.log("categoryId: " + $(this).val())
	      $.getJSON('/asset/items/get_models_ajax',
	                  {catId: $(this).val()},
	                  function(types) {
	                    if(types !== null) {
	                      populateList(types);
	                    }
	        });
	      }
	    });
	});
	 
	function populateList(types) {
	  var options = '';
	 
	  $.each(types, function(index, type) {
	    options += '<option value="' + index + '">' + type.toUpperCase() + '</option>';
	  });
	  $('#ItemTypeId').html(options);
	  $('#types').show();
	 
	}
	
	$(function() {
		$( "#ItemDate" ).datepicker();
	});
	$(document).ready(function(){
		<!--
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		//$( "#ItemDate" ).val(month + "/" + day + "/" + year)
		//-->
	});
</script>

<div class="top-bar">
				<?php echo $this->Html->link(__('Tambah', true), array('action' => 'add'),array('class'=>'button')); ?>
					<h1>Asset</h1>
					<div class="breadcrumbs">
						<a href="/">Laman Utama</a> / <a href="#">Asset</a>
					</div>
</div>
				<br />
				<div class="select-bar">
				<?php
			echo $this->Form->create('Items');
			?>
			<table cellpadding="5" cellspacing="0">
				<tr>
					<td>Kategori :</td>
					<td><?php echo $this->Form->input('category_id',array('empty' => '[SEMUA]','label'=>false));?></td>
					<td>Jenis :</td>
					<td><?php echo '<div id="types" style="display:">';
							echo $this->Form->input('type_id',array('empty' => '[SILA PILIH]','div' => false,'label'=>''));
							echo '</div>';?></td>
					<!-- td>Tarikh Penerimaan :</td>
					<td><input type="text" name="data[Items][received_date]" id="ItemDate"></td -->
					
				</tr>
				<tr>
					<td>Carian Bebas : </td>
					<td><?php echo $this->Form->input('q',array('label'=>false));?></td>
					<td>Tarikh Dari :</td>
					<td><input type="text" value="" id="datefrom"
					name="data[Item][datefrom]" style="width: 80px;"></td>
					<td>Tarikh Sehingga :</td>
					<td><input type="text" value="" id="dateto"
					name="data[Item][dateto]" style="width: 80px;"></td>
				</tr>
			</table>
			<?php
			echo $this->Form->end("Filter");
			?>
</div>
<div class="table">
	<img src="../img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
	<img src="../img/bg-th-right.gif" width="7" height="7" alt=""
		class="right" />
	<table class="listing" cellpadding="0" cellspacing="0">
		<tr>
			<th class="first"><?php echo $this->Paginator->sort('name');?>
			</th>
			<th><?php echo "KEW.PA2";?>
			</th>
			<th><?php echo $this->Paginator->sort('category_id');?>
			</th>
			<th><?php echo $this->Paginator->sort('type_id');?>
			</th>
			<th><?php echo $this->Paginator->sort('received_date');?>
			</th>
			<th class="last actions"><?php __('Actions');?>
			</th>
		</tr>
		
		<?php
				$i = 0;
				foreach ($items as $item):
				$class = null;
				if ($i++ % 2 == 0) {
					$class = ' class="first style1"';
					$tr = ' class="bg"';
				}else {
					$class = ' class="first style2"';
				}
				?>
		<tr <?php echo $tr;?>>
			<td><?php echo $item['Item']['name']; ?>&nbsp;</td>
					<?php
						if($item['Item']['q_pa'] == "" ){
							$serialno = "KDN/PDRM/SMS/CK/PR/09/H/11/".str_pad($item['Item']['id'], 6, '0',STR_PAD_LEFT);
						} else {
							$serialno = $item['Item']['q_pa'];
						}
					?>
					<td><?php 
					echo $this->Html->link($serialno, array('action' => 'view', $item['Item']['id']));?>
					</td>
					<td><?php echo $this->Html->link($item['Category']['name'], array('controller' => 'categories', 'action' => 'view', $item['Category']['id'])); ?>
					</td>
					<td><?php echo $this->Html->link($item['Type']['name'], array('controller' => 'types', 'action' => 'view', $item['Type']['id'])); ?>
					</td>
					<td><?php echo $item['Item']['received_date']; ?>&nbsp;</td>
					<td class="actions">
					<?php 
					echo $this->Html->link($this->Html->image("edit-icon.gif"),array('action' => 'edit', $item['Item']['id']),array('escape' => false));
					echo $this->Html->link($this->Html->image("hr.gif"),array('action' => 'delete', $item['Item']['id']),array('escape' => false), sprintf(__('Are you sure you want to delete # %s?', true), $item['Item']['id']));
					?>
					</td>
		</tr>
		<?php endforeach;?>
	</table>
	<p>
			<?php
			echo $this->Paginator->counter(array(
	'format' => __('Page %page% of %pages%, showing %current% records out of %count% total.', true)
			));
			?>
			</p>

			<div class="paging">
			<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
				|
				<?php echo $this->Paginator->numbers();?>
				|
				<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
			</div>
</div>
<div class="clear"></div>
